package com.kk.common;

import lombok.Data;

/**
 * @author kl
 * @version 1.0
 * @description: TODO
 * @date 2025/10/14 上午10:10
 */
public enum ResultCode implements IResultCode {

    // ==================== 通用状态码 (1xxx) ====================
    SUCCESS(200, "操作成功"),
    FAILED(500, "操作失败"),
    BUSINESS_ERROR(5001, "业务出错"),
    UNAUTHORIZED(5002, "未认证"),
    FORBIDDEN(5003, "权限不足"),
    QUERY_ERROR(5004, "查询出错");

    /**
     * 状态码
     */
    private final Integer code;

    /**
     * 消息
     */
    private final String message;

    ResultCode(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    @Override
    public Integer getCode() {
        return code;
    }

    @Override
    public String getMessage() {
        return message;
    }

    /**
     * 根据状态码获取枚举
     */
    public static ResultCode getByCode(Integer code) {
        if (code == null) {
            return null;
        }
        for (ResultCode resultCode : ResultCode.values()) {
            if (resultCode.getCode().equals(code)) {
                return resultCode;
            }
        }
        return null;
    }

}
